/*
 * Copyright 2013 meichenhui
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.googlecode.zet.tool.pluginanalyzer;

import java.util.jar.Manifest;

import org.apache.commons.lang3.StringUtils;
import org.osgi.framework.Constants;

/**
 * 测试参数准备<br/>
 * 包含了一个插件依赖环境<br/>
 * A,B,C,D,E,F,G,H这8个插件的关系(箭头指向被依赖插件):<br/>
 * <pre>
 *      A       B <-------+ C +---x---+
 *     + +     + +          +         |
 *     | |     | |          |         |
 *     | |     v |          |         x
 *     | +---> E |          |         |
 *     |         |          |         |
 *     v         |          v         v
 *     D <-------+          F         G         H
 * </pre>
 * @author meichenhui
 *
 */
public class BaseTestCase {

    protected static final String validRequiredBundleValue = " org.eclipse.xtext;bundle-version=\"[2.0.0,3.0.0)\",org.eclipse.xtext.generator;resolution:=\"optional\";bundle-version=\"[2.0.0,3.0.0)\",org.apache.commons.logging;resolution:=\"optional\";bundle-version=\"[1.1.0,2.0.0)\",org.eclipse.ui";
    
    protected static final String pluginARequiredBundle = "com.googlecode.zet.tool.pluginanalyzer.d;bundle-version=\"[2.0.0,3.0.0)\",com.googlecode.zet.tool.pluginanalyzer.e;bundle-version=\"[2.0.0,3.0.0)\"";
    
    protected static final String pluginBRequiredBundle = "com.googlecode.zet.tool.pluginanalyzer.d;bundle-version=\"[2.0.0,3.0.0)\",com.googlecode.zet.tool.pluginanalyzer.e;bundle-version=\"[2.0.0,3.0.0)\"";
    
    protected static final String pluginCRequiredBundle = "com.googlecode.zet.tool.pluginanalyzer.b;bundle-version=\"[2.0.0,3.0.0)\",com.googlecode.zet.tool.pluginanalyzer.f;bundle-version=\"[2.0.0,3.0.0)\",com.googlecode.zet.tool.pluginanalyzer.g;bundle-version=\"[2.0.0,3.0.0)\"";
    
    protected Manifest createValidManifest() {
        Manifest validManifest = new Manifest();
        validManifest.getMainAttributes().putValue(Constants.BUNDLE_NAME,"pluginanalyzer");
        validManifest.getMainAttributes().putValue(Constants.BUNDLE_SYMBOLICNAME,"com.googlecode.zet.tool.pluginanalyzer; singleton:=true");
        validManifest.getMainAttributes().putValue(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT,"J2SE-1.5");
        validManifest.getMainAttributes().putValue(Constants.REQUIRE_BUNDLE,
                validRequiredBundleValue);
        validManifest.getMainAttributes().putValue(Constants.BUNDLE_VERSION,"0.8.2.v201301311224");
        return validManifest;
    }
    
    protected Manifest createValidManifestEmptyVersion() {
        Manifest validManifest = new Manifest();
        validManifest.getMainAttributes().putValue(Constants.BUNDLE_NAME,"pluginanalyzer");
        validManifest.getMainAttributes().putValue(Constants.BUNDLE_SYMBOLICNAME,"com.googlecode.zet.tool.pluginanalyzer");
        validManifest.getMainAttributes().putValue(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT,"J2SE-1.5");
        validManifest.getMainAttributes().putValue(Constants.REQUIRE_BUNDLE,
                validRequiredBundleValue);
        return validManifest;
    }
    
    protected SimpleBundleDescription createValidBundleDescription() {
        return new SimpleBundleDescription(createValidManifest());
    }
    
    protected Manifest createPluginAManifest() {
        Manifest validManifest = new Manifest();
        validManifest.getMainAttributes().putValue(Constants.BUNDLE_NAME,"A");
        validManifest.getMainAttributes().putValue(Constants.BUNDLE_SYMBOLICNAME,"com.googlecode.zet.tool.pluginanalyzer.a");
        validManifest.getMainAttributes().putValue(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT,"J2SE-1.5");
        validManifest.getMainAttributes().putValue(Constants.REQUIRE_BUNDLE,
                pluginARequiredBundle);
        validManifest.getMainAttributes().putValue(Constants.BUNDLE_VERSION,"0.8.2.v201301311224");
        return validManifest;
    }
    
    protected Manifest createPluginBManifest() {
        Manifest validManifest = new Manifest();
        validManifest.getMainAttributes().putValue(Constants.BUNDLE_NAME,"B");
        validManifest.getMainAttributes().putValue(Constants.BUNDLE_SYMBOLICNAME,"com.googlecode.zet.tool.pluginanalyzer.b");
        validManifest.getMainAttributes().putValue(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT,"J2SE-1.5");
        validManifest.getMainAttributes().putValue(Constants.REQUIRE_BUNDLE,
                pluginBRequiredBundle);
        validManifest.getMainAttributes().putValue(Constants.BUNDLE_VERSION,"2.8.2.v201301311224");
        return validManifest;
    }
    
    protected Manifest createPluginCManifest() {
        Manifest validManifest = new Manifest();
        validManifest.getMainAttributes().putValue(Constants.BUNDLE_NAME,"C");
        validManifest.getMainAttributes().putValue(Constants.BUNDLE_SYMBOLICNAME,"com.googlecode.zet.tool.pluginanalyzer.c");
        validManifest.getMainAttributes().putValue(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT,"J2SE-1.5");
        validManifest.getMainAttributes().putValue(Constants.REQUIRE_BUNDLE,
                pluginCRequiredBundle);
        validManifest.getMainAttributes().putValue(Constants.BUNDLE_VERSION,"0.8.2.v201301311224");
        return validManifest;
    }
    
    protected Manifest createPluginDManifest() {
        Manifest validManifest = new Manifest();
        validManifest.getMainAttributes().putValue(Constants.BUNDLE_NAME,"D");
        validManifest.getMainAttributes().putValue(Constants.BUNDLE_SYMBOLICNAME,"com.googlecode.zet.tool.pluginanalyzer.d");
        validManifest.getMainAttributes().putValue(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT,"J2SE-1.5");
        validManifest.getMainAttributes().putValue(Constants.BUNDLE_VERSION,"2.8.2.v201301311224");
        return validManifest;
    }
    
    protected Manifest createPluginEManifest() {
        Manifest validManifest = new Manifest();
        validManifest.getMainAttributes().putValue(Constants.BUNDLE_NAME,"E");
        validManifest.getMainAttributes().putValue(Constants.BUNDLE_SYMBOLICNAME,"com.googlecode.zet.tool.pluginanalyzer.e");
        validManifest.getMainAttributes().putValue(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT,"J2SE-1.5");
        validManifest.getMainAttributes().putValue(Constants.BUNDLE_VERSION,"2.8.2.v201301311224");
        return validManifest;
    }
    
    protected Manifest createPluginFManifest() {
        Manifest validManifest = new Manifest();
        validManifest.getMainAttributes().putValue(Constants.BUNDLE_NAME,"F");
        validManifest.getMainAttributes().putValue(Constants.BUNDLE_SYMBOLICNAME,"com.googlecode.zet.tool.pluginanalyzer.f");
        validManifest.getMainAttributes().putValue(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT,"J2SE-1.5");
        validManifest.getMainAttributes().putValue(Constants.BUNDLE_VERSION,"2.5.0.v201301311224");
        return validManifest;
    }
    
    protected Manifest createPluginGManifest() {
        Manifest validManifest = new Manifest();
        validManifest.getMainAttributes().putValue(Constants.BUNDLE_NAME,"G");
        validManifest.getMainAttributes().putValue(Constants.BUNDLE_SYMBOLICNAME,"com.googlecode.zet.tool.pluginanalyzer.g");
        validManifest.getMainAttributes().putValue(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT,"J2SE-1.5");
        validManifest.getMainAttributes().putValue(Constants.BUNDLE_VERSION,"0.8.2.v201301311224");
        return validManifest;
    }
    
    protected Manifest createPluginHManifest() {
        Manifest validManifest = new Manifest();
        validManifest.getMainAttributes().putValue(Constants.BUNDLE_NAME,"H");
        validManifest.getMainAttributes().putValue(Constants.BUNDLE_SYMBOLICNAME,"com.googlecode.zet.tool.pluginanalyzer.h");
        validManifest.getMainAttributes().putValue(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT,"J2SE-1.5");
        validManifest.getMainAttributes().putValue(Constants.BUNDLE_VERSION,"0.8.2.v201301311224");
        return validManifest;
    }

}
